import { observable, action } from 'mobx';
import { WeaForm, WeaTableNew } from 'comsMobx';

const { TableStore } = WeaTableNew;

/**
 * 列表页面，基础store
 */
export default class ListBaseStore {
  @observable comsWeaTableStore = new TableStore();

  /** 页面权限 */
  @observable viewRightInitCompleted = false;
  @observable viewRight = false;

  /** 列表store */
  @observable title = '';
  @observable loading = false; // 加载中状态
  @observable sessionkey = ''; // 表格sessionkey

  /** 高级查询store */
  @observable form = new WeaForm(); // 表单
  @observable showSearchAd = false; // 高级搜索面板是否展示
  @observable conditioninfo = []; // 高级搜索条件

  // 设置标题
  @action setTitle = (title) => {
    this.title = title;
  };

  // 获取form当前的值
  @action getFormParams = () => this.form.getFormParams();

  // 清空高级搜索表单里面所有字段的值
  @action resetAdSearchForm = () => {
    this.form.reset();
  };

  // 展示或隐藏 加载中状态条
  @action showLoading = (bool) => {
    this.loading = bool;
  };

  // 展示或隐藏 高级搜索条件面板
  @action setShowSearchAd = (bool) => {
    this.showSearchAd = bool;
  };

  // 顶部tab标志
  @action setSelectedKey = (selectedKey = '') => {
    this.selectedKey = selectedKey;
  };

  @action initFormFields = (conditioninfo) => {
    this.form.initFormFields(conditioninfo);
  };

  @action setFormFields = (value) => {
    this.form.updateFields(value, true); // true代表完全覆盖方式更新条件值
  };

  @action appendFormFields = (value) => {
    this.form.updateFields(value, false);
  };

  @action clearFormFields = () => {
    this.form.reset(); // 清除查询条件值
  };

  @action setCondition = (conditioninfo) => {
    this.form = new WeaForm(); // 表单
    this.form.setCondition(conditioninfo); // 设置 condition //调用该方法之前 form 需要重新 new 下
  };

  // 重新初始化一个form
  @action reinitializeForm = (conditioninfo) => {
    this.form = new WeaForm();
    this.form.initFormFields(conditioninfo);
  };

  @action setViewRightInitCompleted = () => {
    if (!this.viewRightInitCompleted) {
      this.viewRightInitCompleted = true;
    }
  };
}
